 # -*- coding: utf-8 -*-

from django import template
import pytz, datetime

register = template.Library()

@register.filter
def getpri(pri,content=''):
	cls=['pnone','plow','pmedium','phigh','pcritical']
	try:
		pri=int(pri)
		if pri<5:
			cls=cls[pri]
		else:
			cls='pnone'
		if not content:
			content=pri
			cls=cls+' pripadd'
		return '<span class="priority ui-corner-all %s">%s</span>' % (cls,content)
	except:
		return pri

@register.filter
def local_time(date, request):
    if request.user.is_anonymous() or not isinstance(date, datetime.datetime):
        return date
    timezone = pytz.timezone("Europe/Moscow")
    date = pytz.datetime.datetime(date.year, date.month, date.day, date.hour, date.minute, tzinfo=pytz.utc)
    return date.astimezone(timezone)
